<?php

namespace App\Admin\Controllers;

use App\Models\Position;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class PositionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(Position::with(['user', 'robot.pair.site']), function (Grid $grid) {
            $grid->model()->orderBy('updated_at', 'desc');
            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('user.email', '用户邮箱');
            $grid->column('user.mobile', '用户手机号');
            $grid->column('robot.pair.site.site_name', '交易所');
            $grid->column('robot.pair.symbol', '交易对');
            $grid->column('price');
            $grid->column('amount');
            $grid->column('number');
            $grid->column('fee');
            $grid->column('profit');
            $grid->column('order_number', '系统补仓次数');
            $grid->column('first_number');
            $grid->column('last_price');
            $grid->column('status')->using(['opening'=>'等待信号开仓', 'working' => '工作中', 'closed'=>'已平仓']);
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('user.email', '用户邮箱');
                $filter->equal('user.mobile', '用户手机号');
                $filter->equal('robot.pair.site.site_name', '交易所');
                $filter->equal('robot.pair.symbol', '交易对');
                $filter->equal('status')->select(['opening'=>'等待信号开仓', 'working' => '工作中', 'closed'=>'已平仓']);
            });
            $grid->disableBatchDelete();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }
}
